﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AuctionSite.App_Code.Modelos;
using System.Data.SqlClient;

namespace AuctionSite.App_Code.DAL
{
    public class LanceDAL
    {
        public LanceDAL(){}

        public void Inserir(Lance l){
        
         SqlConnection cn = new SqlConnection();
         try
         {

             cn.ConnectionString = Dados.StringDeConexao;
             //command
             SqlCommand cmd = new SqlCommand();
             cmd.Connection = cn;
            
             var sqlFormattedDate = l.Lance_data.Date.ToString("yyyy-MM-dd HH:mm:ss");
             cmd.CommandText = "UPDATE produtos SET comprador=@comprador, prod_valor=@prod_valor,prod_data_lance=@data WHERE prod_id=@prod_id";
             cmd.Parameters.AddWithValue("@comprador", l.Comprador);
             cmd.Parameters.AddWithValue("@prod_valor", l.Valor);
             cmd.Parameters.AddWithValue("@data", sqlFormattedDate);
             cmd.Parameters.AddWithValue("@prod_id", l.Prod_id);
             cn.Open();
             cmd.ExecuteNonQuery();

             cn.Close();

                          
         }
         catch (SqlException ex) { 
         
         }
        
        
        
        
        }
    }
}